import request from '@/utils/request';

interface ProductItem {
  productId: string;
  productName: string;
  serNum: number;
  hotFlag: string;
  picUrl: string;
  productSimDesc: string;
  productContentBind: string;
  categoryId: string;
  categoryName: string;
}

interface CategoryItem {
  categoryId: string;
  categoryName: string;
}

interface ListResponse {
  list: ProductItem[];
  total: number;
}

export async function qryProductListPage(params: {
  pageIndex?: number;
  pageSize?: number;
  param?: {
    productName?: string;
    [key: string]: any;
  };
}): Promise<ListResponse> {
  const response = await request('/product/qryProductListPage', {
    method: 'POST',
    data: params,
  });
  return {
    list: response.data || [],
    total: response.total || 0,
  };
}

export async function qryMainCategoryList(): Promise<CategoryItem[]> {
  const response = await request('/officalsite/qryMainCategoryList', {
    method: 'POST',
    data: {}
  });
  return response.data || [];
}

export async function qryProductInfoDetail(params: {
  productId: string;
}): Promise<ProductItem> {
  const response = await request('/product/qryProductInfoDetail', {
    method: 'POST',
    data: params,
  });
  return response.data;
}

export async function addProductInfo(params: {
  productName: string;
  serNum?: number;
  categoryId?: string;
  hotFlag?: string;
  picUrl?: string;
  productSimDesc?: string;
  productContentBind?: string;
}): Promise<void> {
  await request('/product/addProductInfo', {
    method: 'POST',
    data: params,
  });
}

export async function updateProductInfo(params: {
  productId: string;
  productName: string;
  serNum?: number;
  categoryId?: string;
  hotFlag?: string;
  picUrl?: string;
  productSimDesc?: string;
  productContentBind?: string;
}): Promise<void> {
  await request('/product/updateProductInfo', {
    method: 'POST',
    data: params,
  });
}

export async function deleteProductInfo(params: {
  productId: string;
}): Promise<void> {
  await request('/product/deleteProductInfo', {
    method: 'POST',
    data: params,
  });
}